//
//  ShopCollectTableViewController.m
//  newProject
//
//  Created by 李航飞 on 2017/6/11.
//  Copyright © 2017年 李航飞. All rights reserved.
//

#import "ShopCollectTableViewController.h"
#import "ShopCollectCell.h"
@interface ShopCollectTableViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, assign)NSInteger indexNum;
@property (nonatomic, strong)UITableView *tableView;
@property (nonatomic, strong)NSMutableArray *dataArray;
@end

@implementation ShopCollectTableViewController
- (void)httpGetData{
    [[MyNetWorking sharedManager]GET_PATH:@"g=portal&m=buyer&a=collect&id=1" success:^(id responseObject) {
        [self.dataArray addObjectsFromArray:responseObject];
        [self createTableView];
    } failure:^(NSError *error) {
        
    }];
}

- (NSMutableArray *)dataArray{
    if (!_dataArray) {
        _dataArray = [[NSMutableArray alloc]init];
    }
    return _dataArray;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden=NO;
    [self.tabBarController.tabBar setHidden:YES];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self httpGetData];
    self.indexNum = 1;
    self.view.backgroundColor = RGB0X(0xF8F9F6);
    self.navigationItem.title = @"商品收藏";
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithTitle:@"编辑" style:UIBarButtonItemStylePlain target:self action:@selector(rightItem:)];
    self.navigationItem.rightBarButtonItem = rightItem;
    self.navigationItem.rightBarButtonItem.tintColor=ALL_COLOR;
//    [self.tableView registerClass:[ShopCollectCell class] forCellReuseIdentifier:@"cell"];
    
}
- (void)rightItem:(UIBarButtonItem *)item{
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)createTableView{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 8/WIDTH_6_SCALE, WIDTH, HIGHT-64-8/WIDTH_6_SCALE) style:UITableViewStylePlain];
    self.tableView.backgroundColor = RGB0X(0xF1F1F1);
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableView];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.dataArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 100*kScrenHidth;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//    NSString *CellIdentifier = [NSString stringWithFormat:@"cell%d",indexPath.row];
//    ShopCollectCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
//    if(cell == nil){
//        cell = [[ShopCollectCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
//    }
//    cell.selectionStyle = UITableViewCellSelectionStyleNone;
//    cell.titleLable.text = @"橙子 地雷西瓜";
//    cell.detailLable.text = @"￥29.9";
//    cell.leftImageView.image=[UIImage imageNamed:@"xigua"];
//    cell.jingXuanImg.image=[UIImage imageNamed:@"jingx2"];
//    cell.block = ^(UIButton *btn) {
//                //[self.tableView reloadData];
////        self.indexNum=cell.numLable.text;
//    };
//    
//    cell.numLable.text = [NSString stringWithFormat:@"%ld",self.indexNum];
//    
//    NSLog(@"%ld",self.indexNum);
//    // Configure the cell...

    NSString *CellIdentifier = [NSString stringWithFormat:@"cell%ld%ld",indexPath.section,indexPath.row];
    
    ShopCollectCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    if (!cell) {
        cell = [[ShopCollectCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }
    cell.detailLable.text = SF(@"¥%@",self.dataArray[indexPath.row][@"price"]) ;
    [cell.leftImageView sd_setImageWithURL:[NSURL URLWithString:SF(@"%@%@",IMAGEURL,self.dataArray[indexPath.row][@"icon"])] placeholderImage:[UIImage imageNamed:@""]];
    cell.jingXuanImg.image=[UIImage imageNamed:@"jingx2"];
    cell.titleLable.text = self.dataArray[indexPath.row][@"name"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.oldPriceLabel.text = SF(@"¥%@",self.dataArray[indexPath.row][@"price_old"]);
//    cell.detailLable.text = [NSString stringWithFormat:@"%ld",indexPath.row];
    cell.block = ^(UIButton *btn) {
        
        
    };
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
